﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/4/2009
 * Time: 9:23 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using NHibernate;
using System.Collections.Generic;
using System.Data;
using PilotFish.Model.Dao.Interface;

namespace PilotFish.Model.Dao.NHibernate
{
	/// <summary>
	/// Description of NHibernatePatientDao.
	/// </summary>
	public class NHibernatePatientDao : IPatientDao
	{
		public NHibernatePatientDao()
		{
		}
		
		public void SaveOrUpdate(Patient patient)
		{
			ISession session = NHibernateHelper.OpenSession();
			session.SaveOrUpdate(patient);
			session.Flush();
		}
		
		public void Delete(Patient patient)
		{
			ISession session = NHibernateHelper.OpenSession();
			session.Delete(patient);
			session.Flush();
		}
		
		public Patient ReadByPk(int id)
		{
			return NHibernateHelper.OpenSession().Load<Patient>(id);
		}
		
		public IList<Patient> FindAll()
		{
			return NHibernateHelper.OpenSession().CreateCriteria(typeof(Patient)).List<Patient>();
		}
	}
}
